package com.api.zszsj2.util;

import com.api.zszsj.yzy.util.LogTool;
import weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.hrm.User;
import weaver.hrm.company.SubCompanyComInfo;

public class HrmCusRight {
    public static final LogTool log = new LogTool("/log/dev/zszsj2/HrmCusRight", false);


	public static String ifMaster4Workplan(User user,String workplanId){
        String isThisWorkplanMaster = "0";
        int userId = user.getUID();
        String uid = String.valueOf(userId);
        if(workplanId==null || workplanId.isEmpty()){
            return "0";
        }
        try {
            RecordSet rs = new RecordSet();
            String sql = "select * from workplan where id=" + workplanId;
            rs.executeQuery(sql);

            if (rs.next()) {
                String subcompanyid = Util.null2String(rs.getString("subcompanyid"));
                if (!"".equals(subcompanyid)) {
                    //判断step1：是否单位日程统筹人
                    RecordSet rs_m = new RecordSet();
                    String sql_m = "select * from uf_unit_wp_master where concat(',',master,',') like ?";
                    rs_m.executeQuery(sql_m, "%," + userId + ",%");
                    while (rs_m.next()) {
                        /* 第一版的时候考虑的是单位是单个
                        //判断step2：统筹人单位是否是日程所属单位或上级单位
                        String masterDw = Util.null2String(rs_m.getString("dw"));
                        if (masterDw.equals(subcompanyid)) {
                            isThisWorkplanMaster = "1";
                            break;
                        }
                        String subCompanyTreeStr = SubCompanyComInfo.getSubCompanyTreeStr(subcompanyid);
                        if (("," + subCompanyTreeStr + ",").indexOf("," + subcompanyid + ",") > -1) {
                            isThisWorkplanMaster = "1";
                            break;
                        }
                        */

                        /* 第二版的时候考虑的是单位是多单位字段*/
                        String masterDw = Util.null2String(rs_m.getString("tcdw"));
                        if ( (","+masterDw+",").indexOf(","+subcompanyid+",")>-1) {
                            isThisWorkplanMaster = "1";
                            break;
                        }

                    }
//                    //是否是部门负责人、分管领导
//                    if(!"1".equals(isThisWorkplanMaster)){
//                        //暂不考虑
//                    }
                }
            }
        }catch(Exception e){
            log.writeLog("Class:HrmCusRight, ifMaster4Workplan Exception:"+ e.getMessage());
        }

        return isThisWorkplanMaster;
    }
}